/*
 * $Id: Udp4Address.cc,v 1.8 2005-07-23 14:05:45 bacon Exp $
 */

#include <xpp/net/Udp4Address.h>
#include <xpp/net/Socket.h>
#include <xp/bas/assert.h>

namespace xpp
{
	namespace net
	{

		Udp4Address::Udp4Address (): UdpAddress (V4)
		{
		}

		Udp4Address::Udp4Address (const InetAddress& adr): UdpAddress (adr)
		{
			xp_assert (this->family() == adr.family());
		}

		Udp4Address::Udp4Address (
			const struct sockaddr_in& adr): UdpAddress (adr)
		{
		}

		Udp4Address::Udp4Address (xp_uint16_t port, xp_uint32_t ip): UdpAddress (V4)
		{
			struct sockaddr_in sin;
			xp_memset (&sin, 0, xp_sizeof(sin));
			sin.sin_family = V4;
			sin.sin_addr.s_addr = ip;
			sin.sin_port = port;
			InetAddress::operator= (sin);
		}
		
		Udp4Address& Udp4Address::operator= (const Udp4Address& adr)
		{
			UdpAddress::operator= (adr);
			return *this;
		}

		Udp4Address& Udp4Address::operator= (const InetAddress& adr)
		{
			xp_assert (this->family() == adr.family());
			UdpAddress::operator= (adr);
			return *this;
		}

		xp_uint16_t Udp4Address::port () const
		{
			struct sockaddr_in* p;
			p = (struct sockaddr_in*)this->storage();
			return p->sin_port;
		}

		xp_uint32_t Udp4Address::ip () const
		{
			struct sockaddr_in* p;
			p = (struct sockaddr_in*)this->storage();
			return p->sin_addr.s_addr;
		}
	}
}
